package com.hex.tcpproxy.process;

import com.hex.tcpproxy.util.ProxyHandler;
import com.hex.tcpproxy.util.ProxyServer;

/**
 * @author: [wujie]
 * @createTime: [2019/10/9 9:17]
 * @description:
 */
public class FakeServer implements Runnable {
    private Integer port;
    private ProxyHandler proxyHandler;
    private ProxyServer server;
    private String remoteAdress;
    private MainServer mainServer;

    public FakeServer(int port, String remoteAdress, MainServer mainServer) {
        this.port = port;
        this.remoteAdress = remoteAdress;
        this.mainServer = mainServer;
    }

    @Override
    public void run() {
        proxyHandler = new ProxyHandler() {
            @Override
            public void read(String address, byte[] bytes) {
                mainServer.sendData(bytes);
            }
        };
        server = new ProxyServer(port, proxyHandler);
        server.bind();
    }


    public String getRemoteAdress() {
        return remoteAdress;
    }

    public void close() {
        server.close();
    }
}
